#include "plic.h"
#include "riscv.h"
#include "platform.h"

volatile plic_t* const plic = (volatile plic_t *)PLIC_BASE_ADDR;

void interrupt_init(void){
    int idx, cpuid;

    cpuid = current_coreid();

    /* Disable all interrupts for the current core. */
    for(idx=0;idx<((PLIC_NUM_SOURCES+32u)/32u);idx++){
	plic->target_enables.target[cpuid].enable[idx]=0;
    }

    /* Set priorityes to zero */
    for(idx=0;idx<PLIC_NUM_SOURCES;idx++){
	plic->source_priorities.priority[idx]=0;
    }

    /* Set the threshold to zero */
    plic->targets.target[cpuid].priority_threshold=0;

    /* Enable machine external interrupts. */
    set_csr(mie, MIP_MEIP);
}
